package servlet;

import com.sun.net.httpserver.HttpPrincipal;
import pojo.Product;
import sevice.ProductService;
import sevice.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/11/26 11:02
 */
public class SetOneProduct extends HttpServlet {
    private ProductService productService = new ProductServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");


        Integer number = Integer.parseInt(req.getParameter("number"));
        Integer productId = Integer.parseInt(req.getParameter("productId"));
        Product product = new Product();
       product.setNumber(number);
       product.setProductId(productId);


        if (productService.setOneProduct(product) > 0) {
            req.setAttribute("message", "新增成功");
        }
        else {
            req.setAttribute("message", "新增失败");
        }

        req.getRequestDispatcher("get_message.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
